/* eslint-disable max-classes-per-file */
/*
 * @Description:高级查询
 * @Version: 2.0
 * @Autor: wiz
 * @Date: 2022-08-01 10:43:06
 * @LastEditors: wiz
 * @LastEditTime: 2023-08-04 11:35:44
 */

import lexicon from '@/lib/lexicon';
import { T_rule } from './base/rule';
import { I_sort, T_sort, V_sortValue } from './base/sort';
import { T_stdReq } from './base/stdReq';
// getPartData API参数接口类
export class T_getPartDataArg extends T_stdReq {
  private url: string = lexicon.url.getPartData;

  pageNo: number;

  pageSize: number;

  globalSearch: string;

  filter: object;

  sort: Array<T_sort>;

  constructor() {
    super();
    this.sort = [];
    this.setRule(new T_rule());
  }

  public setGlobalSearch(p: string): T_getPartDataArg {
    this.globalSearch = p;
    return this;
  }

  public setPageNo(p: number): T_getPartDataArg {
    this.pageNo = p;
    return this;
  }

  public setPageSize(p: number): T_getPartDataArg {
    this.pageSize = p;
    return this;
  }

  public setPage(pageNo, pageSize: number): T_getPartDataArg {
    this.pageSize = pageSize;
    this.pageNo = pageNo;
    return this;
  }

  public setSort(p: T_sort[]): T_getPartDataArg {
    this.sort = p;
    return this;
  }

  public addSort(...p: T_sort[]): T_getPartDataArg {
    this.sort.push(...p);
    return this;
  }

  public setFilter(p: object): T_getPartDataArg {
    this.filter = p;
    return this;
  }

  public addSortItem(
    field: string,
    value: V_sortValue,
    weight: number
  ): T_getPartDataArg {
    this.sort.push({ field, value, weight } as I_sort);
    return this;
  }
}
// getPartData API参数接口
export interface I_getPartDataArg extends T_getPartDataArg {}
/*
{
	"funName": "",//功能名
    "dbType":"mysql",
    "pageNo":1,
    "pageSize":2,
	"lang": "zh-CN",
    "globalSearch": "",//全局模糊搜索
	"filter": {"fieldName1":1,"fieldName2":"2"},  //bson表达式
    "rule": {
		   "QBE": {
			     "funName": "",
			     "fieldName": ""
           },
     "statistics":[  //统计信息
         {
             "alais":"",   //返回的别名不能与查询字段同名
             "pipeline":{} //一个bson管道表达式
         }
     ],
     },
	 "sort": [{
			"field": "title",
			"value": "asc",
			"weight": 0,
		}]
}
*/
